package router

import (
	"api/controller"
	"api/middleware"
	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	_gin := gin.Default()
	_gin.Use(middleware.Cors())
	v1 := _gin.Group("v1")
	{

		v1.POST("/login", controller.UserLogin)
		v1.POST("/register", controller.UserRegister)

		user := v1.Group("user")
		user.Use(middleware.JwtToken())
		{
			user.GET("/auth", controller.UserAuth)
			user.GET("/info",controller.UserInfo)
		}
		device := v1.Group("device")
		device.Use(middleware.JwtToken())
		{
			device.POST("/add",controller.AddDevice)
			device.GET("/devices",controller.GetUserDevice)
			device.GET("/count",controller.GetUserDeviceCount)
			device.GET("/secret",controller.GetDeviceSecret)
			device.GET("/types",controller.GetDeviceTypes)
			device.GET("/delete",controller.DeleteDevice)
			device.GET("/topic",controller.GetDeviceTopic)
		}
	}
	return _gin
}
